package com.keldian.zhbj74.activity;

import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import com.keldian.zhbj74.R;
import com.keldian.zhbj74.fragment.ContentFragment;
import com.keldian.zhbj74.fragment.LeftMenuFragment;

public class MainActivity extends SlidingFragmentActivity {
	
	private static final String TAG_LEFT_MENU = "TAG_LEFT_MENU";
	private static final String TAG_CONTENT = "TAG_CONTENT";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// 侧滑菜单
		setBehindContentView(R.layout.left_menu);
		SlidingMenu slidingMenu = getSlidingMenu();
		slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
		slidingMenu.setBehindOffset(200);
		
		initFragment();
	}

	private void initFragment() {
		FragmentManager fm = getSupportFragmentManager();
		FragmentTransaction ft = fm.beginTransaction();
		ft.replace(R.id.ll_left_menu, new LeftMenuFragment(), TAG_LEFT_MENU);
		ft.replace(R.id.fl_main, new ContentFragment(), TAG_CONTENT);
		ft.commit();	
	}
	
	public LeftMenuFragment getLeftMenuFragment(String tag){
		FragmentManager fm = getSupportFragmentManager();
		LeftMenuFragment fragment = (LeftMenuFragment) fm.findFragmentByTag("TAG_LEFT_MENU");
		return fragment;
	}
	
	// 获取主页fragment对象
		public ContentFragment getContentFragment() {
			FragmentManager fm = getSupportFragmentManager();
			ContentFragment fragment = (ContentFragment) fm
					.findFragmentByTag(TAG_CONTENT);// 根据标记找到对应的fragment
			return fragment;
		}

}
